package com.wuyou.utils;

import cn.hutool.core.util.StrUtil;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * @Description
 * @Author 无忧
 * @Date 2024/1/22 23:02
 */
public class BinaryFile {

    public static byte[] read(File file) throws IOException {
        BufferedInputStream bf = new BufferedInputStream(new FileInputStream(file));
        try {
            byte[] data = new byte[bf.available()];
            bf.read(data);
            return data;
        }finally {
            bf.close();
        }
    }


    public static byte[] read(String bFile) throws IOException {
        return read(new File(bFile).getAbsoluteFile());
    }

    public static void main(String[] args) {
        try {
            byte[] bt = read("test.txt");
            System.out.println(bt);
            String s = StrUtil.utf8Str(bt);
            System.out.println(s);
        }catch (IOException e){
            e.printStackTrace();
        }

    }
}
